package com.servlet.model.base;

/**
 * Lien entre deux contacts dans la base de donnée
 * Chaque contact est en fait une paire de contact.
 * Le premier a initié la demande et le second est celui qui a ou doit accepter.
 * @author Jing Jing
 */
import java.io.Serializable;
import java.sql.Date;

public class Contact implements Serializable {

	private String email_user1;
	private String email_user2;
	/**
	 * True si les contacts se sont bien acceptés
	 */
	private boolean is_accepted;
	private Date date_invitation;
	private Date date_acceptation;

	private boolean is_modified_accepted;
	private boolean is_modified_date_invitation;
	private boolean is_modified_date_acceptation;

	public Contact() {
		email_user1 = null;
		email_user2 = null;
		is_accepted = false;
		date_invitation = null;
		date_acceptation = null;
		is_modified_accepted = false;
		is_modified_date_invitation = false;
		is_modified_date_acceptation = false;
	}

	public Contact(String email_user1, String email_user2, boolean is_accepted,
			Date date_invitation, Date date_acceptation) {
		this.email_user1 = email_user1;
		this.email_user2 = email_user2;
		this.is_accepted = is_accepted;
		this.date_invitation = date_invitation;
		this.date_acceptation = date_acceptation;
		is_modified_accepted = false;
		is_modified_date_invitation = false;
		is_modified_date_acceptation = false;
	}

	public String getEmail_user1() {
		return email_user1;
	}

	public String getEmail_user2() {
		return email_user2;
	}

	public boolean getIs_accepted() {
		return is_accepted;
	}

	public Date getDate_invitation() {
		return date_invitation;
	}

	public Date getDate_acceptation() {
		return date_acceptation;
	}

	public boolean getIs_modified_accepted() {
		return is_modified_accepted;
	}

	public boolean getIs_modified_date_acceptation() {
		return is_modified_date_acceptation;
	}

	public boolean getIs_modified_date_invitation() {
		return is_modified_date_invitation;
	}

	public void setIs_modified_accepted(boolean is_modified_accepted) {
		this.is_modified_accepted = is_modified_accepted;
	}

	public void setIs_modified_date_acceptation(
			boolean is_modified_date_acceptation) {
		this.is_modified_date_acceptation = is_modified_date_acceptation;
	}

	public void setIs_modified_date_invitation(
			boolean is_modified_date_invitation) {
		this.is_modified_date_invitation = is_modified_date_invitation;
	}

	public void setEmail_user1(String email_user1) {
		this.email_user1 = email_user1;
	}

	public void setEmail_user2(String email_user2) {
		this.email_user2 = email_user2;
	}

	public void setIs_accepted(boolean is_accepted) {
		this.is_accepted = is_accepted;
		this.is_modified_accepted = true;
	}

	public void setDate_invitation(Date date_invitation) {
		this.date_invitation = date_invitation;
		this.is_modified_date_invitation = true;
	}

	public void setDate_acceptation(Date date_acceptation) {
		this.date_acceptation = date_acceptation;
		this.is_modified_date_acceptation = true;
	}

	public String generateInsertSQL() {
		String insertSQL = "INSERT INTO contact VALUES ('" + email_user1
				+ "' ,'" + email_user2 + "' ," + is_accepted + " ,'"
				+ date_invitation + "'";

		if (date_acceptation != null)
			insertSQL += ", '" + date_acceptation + "'";
		else
			insertSQL += " , null";

		insertSQL += ")";

		return insertSQL;
	}

	public String generateDeleteSQL() {
		String deleteSQL = "DELETE FROM contact WHERE email_user_1='"
				+ email_user1 + "' AND email_user_2='" + email_user2 + "'";
		return deleteSQL;
	}
}
